import request from '_utils/request'
import qs from 'qs'

// 分类
const classification = (params = {}) => {
  return request.get('/shop/goods/category/all', {
    params
  })
}

// 轮播
const rollingimg = (params = {}) => {
  return request.get('/banner/list', {
    params
  })
}

// 列表
const goodslist = (params = {}) => {
  return request.post('/shop/goods/list/v2', qs.stringify(params))
}

// 详情
const productdetails = (params = {}) => {
  return request.get('/shop/goods/detail', {
    params
  })
}

// 注册
const userRegister = (params = {}) => {
  return request.post('/user/username/register', qs.stringify(params))
}

// 登录
const userLogin = (params = {}) => {
  return request.post('/user/username/login', qs.stringify(params))
}

// 加购
const addCart = (params = {}) => {
  return request.post('/shopping-cart/add', qs.stringify(params))
}

// 购物车列表
const cartList = (params = {}) => {
  return request.get('/shopping-cart/info', {
    params
  })
}

// 购物车单个商品数量
const setGoodsNum = (params = {}) => {
  return request.post('/shopping-cart/modifyNumber', qs.stringify(params))
}

// 购物车单个商品选中情况
const setGoodsChecked = (params = {}) => {
  return request.post('/shopping-cart/select', qs.stringify(params))
}

// 删除购物车商品
const delGoods = (params = {}) => {
  return request.post('/shopping-cart/remove', qs.stringify(params))
}

// 订单创建
const createOrder = (params = {}) => {
  return request.post('/order/create', qs.stringify(params))
}

// 新增联系人
const addContact = (params = {}) => {
  return request.post('/user/shipping-address/add', qs.stringify(params))
}

// 获取联系人
const getContacts = (params = {}) => {
  return request.post('/user/shipping-address/list/v2', qs.stringify(params))
}

// 获取某个联系人详情
const getContactmsg = (params = {}) => {
  return request.get('/user/shipping-address/detail/v2', {
    params
  })
}

// 获取联系人
const updateContact = (params = {}) => {
  return request.post('/user/shipping-address/update', qs.stringify(params))
}

// 删除联系人
const delContact = (params = {}) => {
  return request.post('/user/shipping-address/delete', qs.stringify(params))
}

// 获取用户信息
const getusermsg = (params = {}) => {
  return request.get('/user/detail', {
    params
  })
}

// 修改用户信息
const changeuser = (params = {}) => {
  return request.post('/user/modify', qs.stringify(params))
}

// 上传头像
const changeheadimg = (params) => {
  return request.post('/dfs/upload/file', params)
}

// 是否收藏
const favorYesorNo = (params = {}) => {
  return request.get('/shop/goods/fav/check', {
    params
  })
}

// 加入收藏
const addfavor = (params = {}) => {
  return request.post('/shop/goods/fav/add', qs.stringify(params))
}

// 删除收藏
const delfavor = (params = {}) => {
  return request.post('/shop/goods/fav/delete', qs.stringify(params))
}

// 收藏列表
const listfavor = (params = {}) => {
  return request.post('/shop/goods/fav/list', qs.stringify(params))
}

export {
  classification,
  rollingimg,
  goodslist,
  productdetails,
  userRegister,
  userLogin,
  addCart,
  cartList,
  setGoodsNum,
  setGoodsChecked,
  delGoods,
  createOrder,
  addContact,
  getContacts,
  getContactmsg,
  updateContact,
  delContact,
  getusermsg,
  changeuser,
  changeheadimg,
  favorYesorNo,
  addfavor,
  delfavor,
  listfavor
}
